#pragma once
#include "RBTree.h"

//template <class Key, class Compare = less<Key>, class Alloc = alloc>
//class set
//{
//public:
//	typedef Key key_type;
//	typedef Key value_type;
//	typedef Compare key_compare;
//	typedef Compare value_compare;
//private:
//	typedef rb_tree<key_type, value_type,identity<value_type>, key_compare, Alloc> rep_type;
//	rep_type t;
//};

namespace xy
{
	template <class T>
	class set
	{
	public:
		struct SetKeyOfT
		{
			const T& operator()(const T& key)
			{
				return key;
			}
		};
		//typedef typename RBTreeIterator<T, const T&, T*> iterator;
		//typedef typename RBTreeIterator<T, const T&, const T*> const_iterator;
		typedef typename RBTree<T, const T, SetKeyOfT>::iterator iterator;
		typedef typename RBTree<T, const T, SetKeyOfT>::Const_iterator const_iterator;
		
		

		pair<iterator,bool> insert(const T& data)
		{
			return _t.Insert(data);
		}

		const_iterator begin() const
		{
			return _t.Begin();
		}

		const_iterator end() const
		{
			return _t.End();
		}

		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

	private:
		RBTree<T,const T, SetKeyOfT> _t;

	};

	void TestMyset()
	{
		set<int> s1;
		s1.insert(1);
		s1.insert(3);
		s1.insert(5);
		s1.insert(2);
		s1.insert(7);
		s1.insert(9);
		set<int>::iterator it1 = s1.begin();
		while (it1 != s1.end())
		{
			//*it1 += 5;
			cout << *it1 << " ";
			++it1;
		}
		cout << endl;
		const set<int> s2 = s1;
		set<int>::const_iterator it2 = s2.begin();
		while (it2 != s2.end())
		{
			cout << *it2 << " ";
			++it2;
		}
	}
}